# 嵌套装饰器
# 当嵌套了多个装饰器时,会按照装饰器应用的顺序,从上到下依次调用
import functools


def decorator1(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('decorator1')
        return f(*args, **kwargs)

    return wrapper


def decorator2(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('decorator2')
        return f(*args, **kwargs)

    return wrapper


def decorator3(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('decorator3')
        return f(*args, **kwargs)

    return wrapper


# 在函数上应用多个装饰器,实际是从上到下顺序调用装饰器
@decorator1
@decorator2
@decorator3
def print_msg(msg):
    print(f'got message: {msg}')


if __name__ == '__main__':
    print_msg('hello')
